// 社区首页
//  MZY_CommunityViewController.m
//  FullHouse
//
//  Created by dllo on 16/1/15.
//  Copyright © 2016年 yy. All rights reserved.
//

#import "MZY_CommunityViewController.h"
#import "NetworkingTool.h"
#import "MZY_RenovateModel.h"
#import "MZY_HomeModel.h"
#import "MZY_renovatePicture.h"
#import "MZY_RenovateIntroduce.h"
#import "MZY_HomeCell.h"
#import "UIImageView+WebCache.h"
#import "MBProgressHUD.h"
#import "MZY_DiscussCollectionView.h"
#import "MZY_TableCollectionView.h"
#import "MZY_COM_detailViewController.h"
#import "MZY_HOME_detailViewController.h"
#import "MJRefresh.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#define HORIZONTAL [UIScreen mainScreen].bounds.size.width / 414
#define VERTICAL [UIScreen mainScreen].bounds.size.height / 736

@interface MZY_CommunityViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic, retain)UIButton *renovateButton;
@property(nonatomic, retain)UIButton *homeButton;
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, assign)BOOL isRenovate;
@property(nonatomic, retain)UITableView *renovateTableView;
@property(nonatomic, retain)NSMutableArray *renovateArr;
@property(nonatomic, retain)UITableView *homeTableView;
@property(nonatomic, retain)NSMutableArray *homeArr;
@property(nonatomic, retain)MBProgressHUD *hud;
@property(nonatomic, retain)UIView *denovateView;
@property(nonatomic, retain)UIView *discussView;
@property(nonatomic, retain)UICollectionView *rightCollectionView;
@property(nonatomic, retain)NSMutableArray *dataArr;
@property(nonatomic, retain)NSMutableArray *titleArr;
@property(nonatomic, retain)UICollectionView *backCollectionView;
@property(nonatomic, retain)UIView *rollView;
@property(nonatomic, assign)NSInteger num;

@end

@implementation MZY_CommunityViewController

- (void)dealloc
{
    [self.renovateButton release];
    [self.homeButton release];
    [self.scrollView release];
    [self.renovateTableView release];
    [self.renovateArr release];
    [self.homeTableView release];
    [self.homeArr release];
    [self.hud release];
    [self.denovateView release];
    [self.discussView release];
    [self.rightCollectionView release];
    [self.dataArr release];
    [self.titleArr release];
    [self.backCollectionView release];
    [self.rollView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createView];
    [self createData];
}

#pragma mark 获取数据
- (void)createData{
    [NetworkingTool networkingWithStrURL:@"http://api.meilijia.com/app/ba_diary_book_list?page=1&type=2&sort=" type:GETType bodyStr:nil block:^(id result) {
        self.renovateArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"ba_diary_book_list"][@"list"]) {
            MZY_RenovateModel *renovate = [[MZY_RenovateModel alloc]init];
            [renovate setValuesForKeysWithDictionary:temp];
            [self.renovateArr addObject:renovate];
            [renovate release];
        }
        [self.renovateTableView reloadData];
        self.hud.hidden = YES;
    }];
    [NetworkingTool networkingWithStrURL:@"http://api.meilijia.com/app/showhome_list?page=1" type:GETType bodyStr:nil block:^(id result) {
        self.homeArr = [NSMutableArray array];
        for (NSDictionary *temp in result[@"data"][@"showhome_list"][@"collections"]) {
            MZY_HomeModel *home = [[MZY_HomeModel alloc]init];
            [home setValuesForKeysWithDictionary:temp];
            [self.homeArr addObject:home];
            [home release];
        }
        [self.homeTableView reloadData];
    }];
}

- (void)loadData{
    NSString *strR = [NSString stringWithFormat:@"http://api.meilijia.com/app/ba_diary_book_list?page=%ld&type=2&sort=",self.num ++];
    [NetworkingTool networkingWithStrURL:strR type:GETType bodyStr:nil block:^(id result) {
        for (NSDictionary *temp in result[@"data"][@"ba_diary_book_list"][@"list"]) {
            MZY_RenovateModel *renovate = [[MZY_RenovateModel alloc]init];
            [renovate setValuesForKeysWithDictionary:temp];
            [self.renovateArr addObject:renovate];
            [renovate release];
        }
        [self.renovateTableView reloadData];
        self.hud.hidden = YES;
    }];
    NSString *strH = [NSString stringWithFormat:@"http://api.meilijia.com/app/showhome_list?page=%ld",self.num ++];
    [NetworkingTool networkingWithStrURL:strH type:GETType bodyStr:nil block:^(id result) {
        for (NSDictionary *temp in result[@"data"][@"showhome_list"][@"collections"]) {
            MZY_HomeModel *home = [[MZY_HomeModel alloc]init];
            [home setValuesForKeysWithDictionary:temp];
            [self.homeArr addObject:home];
            [home release];
        }
        [self.homeTableView reloadData];
    }];
}

#pragma mark 创建界面
- (void)createView{
    
    // 自定义标题
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"装修吧",@"讨论区"]];
    seg.frame =CGRectMake(0, 100, 150, 30);
    seg.tintColor = [UIColor orangeColor];
    self.navigationItem.titleView = seg;
    [seg addTarget:self action:@selector(titleAction:) forControlEvents:UIControlEventValueChanged];
    seg.selectedSegmentIndex = 0;
    [seg release];
    
    // 分隔线
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 1)];
    textField.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:textField];
    [textField release];
    
    // 装修吧"view"
    self.denovateView = [[UIView alloc] initWithFrame:CGRectMake(0, 1, WIDTH, HEIGHT - 64 - 49)];
    [self.view addSubview:self.denovateView];
    [self.denovateView release];
    
    // 讨论区"view"
    self.discussView = [[UIView alloc] initWithFrame:CGRectMake(0, 1, WIDTH, HEIGHT - 64 - 49)];
    self.discussView.backgroundColor = [UIColor yellowColor];
    [self.discussView release];
    
    // 创建一个左边的空白"view"
    UIView *leftTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 30)];
    leftTopView.backgroundColor = [UIColor whiteColor];
    [self.denovateView addSubview:leftTopView];
    [leftTopView release];
    
    // 创建一个右边白色的"collectionView";
    UICollectionViewFlowLayout *rightFlowLayout = [[UICollectionViewFlowLayout alloc]init];
    rightFlowLayout.itemSize = CGSizeMake(50 * HORIZONTAL, 20 * VERTICAL);
    rightFlowLayout.minimumInteritemSpacing = 5 * HORIZONTAL;
    rightFlowLayout.minimumLineSpacing = 10 * VERTICAL;
    rightFlowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
//    rightFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.rightCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 30) collectionViewLayout:rightFlowLayout];
    self.rightCollectionView.scrollEnabled = YES;
    self.rightCollectionView.backgroundColor = [UIColor whiteColor];
    [self.discussView addSubview:self.rightCollectionView];
    self.rightCollectionView.showsHorizontalScrollIndicator = NO;
    self.rightCollectionView.dataSource = self;
    self.rightCollectionView.delegate = self;
    [self.rightCollectionView registerClass:[MZY_DiscussCollectionView class] forCellWithReuseIdentifier:@"title"];
    [self.rightCollectionView release];
    
    // 创建一个"view"滚动条
    self.rollView = [[UIView alloc] initWithFrame:CGRectMake(0, 27, WIDTH / 7, 3)];
    self.rollView.backgroundColor = [UIColor orangeColor];
    [self.rightCollectionView addSubview:self.rollView];
    [self.rollView release];
    
    // 创建一个下边白色的"collectionView";
    UICollectionViewFlowLayout *backFlowLayout = [[UICollectionViewFlowLayout alloc]init];
    backFlowLayout.itemSize = CGSizeMake(WIDTH - 10, HEIGHT);
    backFlowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    backFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.backCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 30, WIDTH, HEIGHT - 49 - 64 - 30) collectionViewLayout:backFlowLayout];
    self.backCollectionView.scrollEnabled = YES;
    self.backCollectionView.pagingEnabled = YES;
    self.backCollectionView.contentSize = CGSizeMake(WIDTH, 0);
    self.backCollectionView.showsHorizontalScrollIndicator = NO;
    self.backCollectionView.backgroundColor = [UIColor cyanColor];
    [self.discussView addSubview:self.backCollectionView];
    self.backCollectionView.dataSource = self;
    self.backCollectionView.delegate = self;
    [self.backCollectionView registerClass:[MZY_TableCollectionView class] forCellWithReuseIdentifier:@"back"];
    [self.backCollectionView release];
    
    self.dataArr = [NSMutableArray arrayWithObjects:@"http://api.meilijia.com/app/topic_list?page=1&sort=",@"http://api.meilijia.com/app/topic_list?page=1&class_id=9&sort=",@"http://api.meilijia.com/app/topic_list?page=1&class_id=1&sort=",@"http://api.meilijia.com/app/topic_list?page=1&class_id=3&sort=",@"http://api.meilijia.com/app/topic_list?page=1&class_id=4&sort=",@"http://api.meilijia.com/app/topic_list?page=1&class_id=6&sort=",@"http://api.meilijia.com/app/topic_list?page=1&class_id=8&sort=", nil];
    
    self.titleArr = [NSMutableArray arrayWithObjects:@"全部",@"图片提问",@"户型",@"设计",@"施工",@"产品选购",@"其它", nil];
    
    // 创建装修中"button"
    self.renovateButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.renovateButton.frame = CGRectMake(140 * HORIZONTAL, 0, 60 * HORIZONTAL, 30 * VERTICAL);
    [self.renovateButton setTitle:@"装修中" forState:UIControlStateNormal];
    [self.renovateButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [leftTopView addSubview:self.renovateButton];
    [self.renovateButton addTarget:self action:@selector(renovateAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 创建已晒家"button"
    self.homeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.homeButton.frame = CGRectMake(220 * HORIZONTAL, 0, 60 * HORIZONTAL, 30 * VERTICAL);
    [self.homeButton setTitle:@"已晒家" forState:UIControlStateNormal];
    [self.homeButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [leftTopView addSubview:self.homeButton];
    [self.homeButton addTarget:self action:@selector(homeAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 创建左边"scrollView"
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30 * VERTICAL, WIDTH  , HEIGHT - 64 - 49)];
    self.scrollView.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:self.scrollView];
    self.scrollView.contentOffset = CGPointMake(0, 0);
    self.scrollView.contentSize = CGSizeMake(WIDTH * 2, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.delegate = self;
    [self.scrollView release];

    self.isRenovate = NO;
    
    // 创建左边的"tableView"
    self.renovateTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, HEIGHT - 49 - 64 - 31 - 20 * VERTICAL) style:UITableViewStylePlain];
    self.renovateTableView.backgroundColor = [UIColor cyanColor];
    [self.scrollView addSubview:self.renovateTableView];
    self.renovateTableView.rowHeight = 310;
    self.renovateTableView.delegate = self;
    self.renovateTableView.dataSource = self;
    [self.renovateTableView registerClass:[MZY_renovatePicture class] forCellReuseIdentifier:@"picture"];
    [self.renovateTableView registerClass:[MZY_RenovateIntroduce class] forCellReuseIdentifier:@"introduce"];
    [self.renovateTableView release];
    
    // 创建右边的"tableView"
    self.homeTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH + 10, 10, WIDTH - 20, HEIGHT - 49 - 64 - 31 - 20) style:UITableViewStylePlain];
    self.homeTableView.backgroundColor = [UIColor cyanColor];
    [self.scrollView addSubview:self.homeTableView];
    self.homeTableView.rowHeight = 350;
    self.homeTableView.delegate = self;
    self.homeTableView.dataSource = self;
    [self.homeTableView registerClass:[MZY_HomeCell class] forCellReuseIdentifier:@"home"];
    [self.homeTableView release];
    
    // 加载动画
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    self.num = 2;
    // 下拉刷新
    [self.renovateTableView addHeaderWithTarget:self action:@selector(refreshView)];
    self.renovateTableView.headerRefreshingText = @"松开即可刷新";
    [self.homeTableView addHeaderWithTarget:self action:@selector(refreshView)];
    self.homeTableView.headerRefreshingText = @"松开即可刷新";
    // 上拉加载
    [self.renovateTableView addFooterWithTarget:self action:@selector(loadDataView)];
    self.renovateTableView.footerRefreshingText = @"请耐心等待,正在为您加载...";
    [self.homeTableView addFooterWithTarget:self action:@selector(loadDataView)];
    self.homeTableView.footerRefreshingText = @"请耐心等待,正在为您加载...";
}

#pragma mark 执行刷新
- (void)refreshView{
    [self createData];
    [self.renovateTableView reloadData];
    [self.homeTableView reloadData];
    [self.renovateTableView headerEndRefreshing];
    [self.homeTableView headerEndRefreshing];
}

#pragma mark 执行加载
- (void)loadDataView{
    [self loadData];
    [self.renovateTableView reloadData];
    [self.homeTableView reloadData];
    [self.renovateTableView footerEndRefreshing];
    [self.homeTableView footerEndRefreshing];
}

#pragma mark "tableView"的第一个必须执行的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.renovateTableView == tableView) {
        return self.renovateArr.count;
    }else{
        return self.homeArr.count;
    }
}

#pragma mark "tableView"的第二个必须执的方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.renovateTableView  == tableView) {
        MZY_RenovateModel *renovate = self.renovateArr[indexPath.row];
        if (renovate.diary_pics.count != 0) {
            self.renovateTableView.rowHeight = 310 * HORIZONTAL;
            MZY_renovatePicture *cell = [tableView dequeueReusableCellWithIdentifier:@"picture" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellEditingStyleNone;
            [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:renovate.author_face]];
            cell.authorImageView.layer.cornerRadius = 25 * HORIZONTAL;
            cell.authorImageView.layer.masksToBounds = YES;
            cell.titleLabel.text = renovate.col_name;
            cell.titleLabel.textColor = [UIColor lightGrayColor];
            [cell.likeButton setImage:[UIImage imageNamed:@"zan.png"] forState:UIControlStateNormal];
            [cell.likeButton addTarget:self action:@selector(zanAction:) forControlEvents:UIControlEventTouchUpInside];
            cell.likeLabel.text = renovate.liked_count;
            cell.introduceLabel.text = renovate.diary_content;
            cell.introduceLabel.font = [UIFont systemFontOfSize:15 * HORIZONTAL];
            cell.introduceLabel.numberOfLines = 0;
            [cell.introduceLabel sizeToFit];
            cell.ornamentLabel.text = renovate.section_name;
            cell.ornamentLabel.layer.cornerRadius = 5 * HORIZONTAL;
            cell.ornamentLabel.font = [UIFont systemFontOfSize:15];
            cell.ornamentLabel.textAlignment = NSTextAlignmentCenter;
            cell.ornamentLabel.layer.masksToBounds = YES;
            cell.ornamentLabel.backgroundColor = [UIColor orangeColor];
            cell.ornamentLabel.textColor = [UIColor whiteColor];
            cell.messageImageView.image = [UIImage imageNamed:@"iconfont-xiaoxixuanzhong-2.png"];
            cell.messageCountLabel.text = renovate.comment_count;
            cell.messageCountLabel.font = [UIFont systemFontOfSize:15];
            cell.viewImageView.image = [UIImage imageNamed:@"iconfont-01.png"];
            cell.viewCountLabel.text = renovate.view_count;
            cell.viewCountLabel.font = [UIFont systemFontOfSize:15];
            if (renovate.info_count.count == 1) {
                cell.graduationLabel.text = renovate.info_count[0][@"name"];
                cell.graduationLabel.font = [UIFont systemFontOfSize:13];
                cell.graduationCountLabel.text = renovate.info_count[0][@"value"];
                cell.graduationCountLabel.font = [UIFont systemFontOfSize:13];
            }else if (renovate.info_count.count == 2){
                cell.graduationLabel.text = renovate.info_count[0][@"name"];
                cell.graduationLabel.font = [UIFont systemFontOfSize:13];
                cell.graduationCountLabel.text = renovate.info_count[0][@"value"];
                cell.graduationCountLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryLabel.text = renovate.info_count[1][@"name"];
                cell.diaryLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryCountLabel.text = renovate.info_count[1][@"value"];
                cell.diaryCountLabel.font = [UIFont systemFontOfSize:13];
            }else{
                cell.graduationLabel.text = renovate.info_count[0][@"name"];
                cell.graduationLabel.font = [UIFont systemFontOfSize:13];
                cell.graduationCountLabel.text = renovate.info_count[0][@"value"];
                cell.graduationCountLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryLabel.text = renovate.info_count[1][@"name"];
                cell.diaryLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryCountLabel.text = renovate.info_count[1][@"value"];
                cell.diaryCountLabel.font = [UIFont systemFontOfSize:13];
                cell.inventoryLabel.text = renovate.info_count[2][@"name"];
                cell.inventoryLabel.font = [UIFont systemFontOfSize:13];
                cell.inventoryCountLabel.text = renovate.info_count[2][@"value"];
                cell.inventoryCountLabel.font = [UIFont systemFontOfSize:13];
            }
            if (renovate.diary_pics.count == 1) {
                [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:renovate.diary_pics[0][@"pic"]]];
                cell.midImageView.image = [UIImage imageNamed:@"iconfont-kongbai-2.png"];
                cell.rightImageView.image = [UIImage imageNamed:@"iconfont-kongbai-2.png"];

            }else if (renovate.diary_pics.count == 2){
                [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:renovate.diary_pics[0][@"pic"]]];
                [cell.midImageView sd_setImageWithURL:[NSURL URLWithString:renovate.diary_pics[1][@"pic"]]];
                cell.rightImageView.image = [UIImage imageNamed:@"iconfont-kongbai-2.png"];
            }else{
                [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:renovate.diary_pics[0][@"pic"]]];
                [cell.midImageView sd_setImageWithURL:[NSURL URLWithString:renovate.diary_pics[1][@"pic"]]];
                [cell.rightImageView sd_setImageWithURL:[NSURL URLWithString:renovate.diary_pics[2][@"pic"]]];
            }
            return cell;
        }else{
            MZY_RenovateIntroduce *cell = [tableView dequeueReusableCellWithIdentifier:@"introduce" forIndexPath:indexPath];
            self.renovateTableView.rowHeight = 180 * HORIZONTAL;
            cell.selectionStyle = UITableViewCellEditingStyleNone;
            [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:renovate.author_face]];
            cell.authorImageView.layer.cornerRadius = 25 * HORIZONTAL;
            cell.authorImageView.layer.masksToBounds = YES;
            cell.titleLabel.text = renovate.col_name;
            cell.titleLabel.textColor = [UIColor lightGrayColor];
            [cell.likeButton setImage:[UIImage imageNamed:@"zan.png"] forState:UIControlStateNormal];
            [cell.likeButton addTarget:self action:@selector(zanAction:) forControlEvents:UIControlEventTouchUpInside];
            cell.likeLabel.text = renovate.liked_count;
            cell.introduceLabel.text = renovate.diary_content;
            cell.introduceLabel.font = [UIFont systemFontOfSize:15 * HORIZONTAL];
            cell.introduceLabel.numberOfLines = 0;
            [cell.introduceLabel sizeToFit];
            cell.ornamentLabel.text = renovate.section_name;
            cell.ornamentLabel.layer.cornerRadius = 5;
            cell.ornamentLabel.font = [UIFont systemFontOfSize:15];
            cell.ornamentLabel.textAlignment = NSTextAlignmentCenter;
            cell.ornamentLabel.layer.masksToBounds = YES;
            cell.ornamentLabel.backgroundColor = [UIColor orangeColor];
            cell.ornamentLabel.textColor = [UIColor whiteColor];
            cell.messageImageView.image = [UIImage imageNamed:@"iconfont-xiaoxixuanzhong-2.png"];
            cell.messageCountLabel.text = renovate.comment_count;
            cell.messageCountLabel.font = [UIFont systemFontOfSize:15];
            cell.viewImageView.image = [UIImage imageNamed:@"iconfont-01.png"];
            cell.viewCountLabel.text = renovate.view_count;
            cell.viewCountLabel.font = [UIFont systemFontOfSize:15];
            if (renovate.info_count.count == 1) {
                cell.graduationLabel.text = renovate.info_count[0][@"name"];
                cell.graduationLabel.font = [UIFont systemFontOfSize:13];
                cell.graduationCountLabel.text = renovate.info_count[0][@"value"];
                cell.graduationCountLabel.font = [UIFont systemFontOfSize:13];
            }else if (renovate.info_count.count == 2){
                cell.graduationLabel.text = renovate.info_count[0][@"name"];
                cell.graduationLabel.font = [UIFont systemFontOfSize:13];
                cell.graduationCountLabel.text = renovate.info_count[0][@"value"];
                cell.graduationCountLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryLabel.text = renovate.info_count[1][@"name"];
                cell.diaryLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryCountLabel.text = renovate.info_count[1][@"value"];
                cell.diaryCountLabel.font = [UIFont systemFontOfSize:13];
            }else{
                cell.graduationLabel.text = renovate.info_count[0][@"name"];
                cell.graduationLabel.font = [UIFont systemFontOfSize:13];
                cell.graduationCountLabel.text = renovate.info_count[0][@"value"];
                cell.graduationCountLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryLabel.text = renovate.info_count[1][@"name"];
                cell.diaryLabel.font = [UIFont systemFontOfSize:13];
                cell.diaryCountLabel.text = renovate.info_count[1][@"value"];
                cell.diaryCountLabel.font = [UIFont systemFontOfSize:13];
                cell.inventoryLabel.text = renovate.info_count[2][@"name"];
                cell.inventoryLabel.font = [UIFont systemFontOfSize:13];
                cell.inventoryCountLabel.text = renovate.info_count[2][@"value"];
                cell.inventoryCountLabel.font = [UIFont systemFontOfSize:13];
            }
            return cell;
        }
    }else{
        MZY_HomeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"home" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        MZY_HomeModel *home = self.homeArr[indexPath.row];
        [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:home.cover_pic]];
        [cell.authorImageView sd_setImageWithURL:[NSURL URLWithString:home.author_face]];
        cell.authorImageView.layer.cornerRadius = 25;
        cell.authorImageView.layer.masksToBounds  =YES;
        cell.titleLabel.text = home.title;
        cell.introduceLabel.text = home.title_sub;
        [cell.likeButton setImage:[UIImage imageNamed:@"zan.png"] forState:UIControlStateNormal];
        [cell.likeButton addTarget:self action:@selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
        cell.likeCountLabel.text = home.liked_count;
        return cell;
    }
}

#pragma mark "tableView"的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.renovateTableView == tableView) {
        self.hidesBottomBarWhenPushed = YES;
        MZY_COM_detailViewController *comVC = [[MZY_COM_detailViewController alloc]init];
        [self.navigationController pushViewController:comVC animated:YES];
        MZY_RenovateModel *renovate = self.renovateArr[indexPath.row];
        comVC.idStr = renovate.col_id;
        self.hidesBottomBarWhenPushed = NO;
    }else{
        self.hidesBottomBarWhenPushed = YES;
        MZY_HOME_detailViewController *homeVC = [[MZY_HOME_detailViewController alloc]init];
        [self.navigationController pushViewController:homeVC animated:YES];
        MZY_HomeModel *home = self.homeArr[indexPath.row];
        homeVC.idStr = home.ID;
        self.hidesBottomBarWhenPushed = NO;
    }
}

#pragma mark 根据偏移量切换"button"方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (self.backCollectionView == scrollView) {
        CGFloat xView = self.backCollectionView.contentOffset.x / 7;
        self.rollView.frame = CGRectMake(xView, 27, WIDTH / 7, 3);
    }else{
        if (self.scrollView.contentOffset.x / WIDTH == 0) {
            [self.renovateButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
            [self.homeButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        }else{
            [self.renovateButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [self.homeButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        }
    }
}

#pragma mark 标题"button"的点击方法
- (void)titleAction:(UISegmentedControl *)seg{
    NSInteger index = seg.selectedSegmentIndex;
    switch (index) {
        case 0:
            [self.discussView removeFromSuperview];
            break;
        case 1:
            [self.view addSubview:self.discussView];
            break;
        default:
            break;
    }
}

#pragma mark 装修中"button"的点击方法
- (void)renovateAction:(UIButton *)button{
    if (self.isRenovate == NO) {
        self.scrollView.contentOffset = CGPointMake(0, 0);
        [self.renovateButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.homeButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    }
    else{
        [self.renovateButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.homeButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
}

#pragma mark 已晒家"button"的点击方法
- (void)homeAction:(UIButton *)button{
    if (self.isRenovate == NO) {
        self.scrollView.contentOffset = CGPointMake(WIDTH, 0);
        [self.renovateButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.homeButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
    else{
        [self.renovateButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.homeButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
}

#pragma mark 赞"button"的点击方法
- (void)zanAction:(UIButton *)button{
    
}

#pragma mark 喜欢"button"的点击方法
- (void)likeAction:(UIButton *)button{
    
}

#pragma mark 右边"collectionView"的第一个必须执行的方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.titleArr.count;
}

#pragma mark 右边"collectionView"的第二个必须执行的方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.rightCollectionView == collectionView) {
        MZY_DiscussCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"title" forIndexPath:indexPath];
        cell.titleLabel.text = self.titleArr[indexPath.row];
        cell.titleLabel.font = [UIFont systemFontOfSize:12];
        cell.titleLabel.textAlignment = NSTextAlignmentCenter;
        return cell;
    }else{
        MZY_TableCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"back" forIndexPath:indexPath];
        cell.urlStr = [self.dataArr objectAtIndex:indexPath.row];
        return cell;
    }
}

#pragma mark "collectionView"的点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.rightCollectionView == collectionView) {
        [self.backCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
        self.rollView.frame = CGRectMake(indexPath.row * (WIDTH / 7), 27, WIDTH / 7, 3);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
